<?php
namespace App\Http\Controllers\Api;

use App\Http\Requests\AddOrderReq;
use App\Services\Check;
use Illuminate\Http\Request;

/**
 * @title 查询接口
 * @description
 * @group 用户端
 * @header name:Authorization type:string require:0 default: other: desc:Authorization
 */
class IndexController extends  BaseController
{

    /**
     * @title 登录
     * @description
     * @author fzf
     * @url /api/login
     * @method post
     * @param name:platform type:string require:1 default:miniapp other: desc:平台：miniapp,h5
     * @param name:code type:string require:0 default: other: desc:小程序登录的code
     */
    function login(Request $request,Check $check){
        $platform=$request->input('platform','miniapp');
        $code=$request->input('code','');
        return $this->success($check->login($platform,$code));
    }

    /**
     * @title 订单列表
     * @description
     * @param name:report type:int require:0 default:0 other: desc:是否是报告
     * @param name:page type:int require:0 default:1 other: desc:当前页数
     * @param name:size type:int require:0 default:10 other: desc:每页记录数
     * @author fzf
     * @url /api/order
     * @method get
     */
    function orders(Request $request,Check $check){
        $size=$request->input('size',15);
        $report=$request->input('report',0);
        return $this->success($check->orders($report,$size));
    }

    /**
     * @title 添加订单
     * @description
     * @param name:type type:int require:0 default:1 other: desc:类型，1=个人2=企业
     * @param name:name type:string require:1 default: other: desc:姓名或者企业名
     * @param name:code type:string require:1 default: other: desc:身份证号或者企业营业执照编号
     * @author fzf
     * @url /api/order
     * @method post
     */
    function add(AddOrderReq $request,Check $check){
        $param=$request->input();
        return $this->success( $check->add($param['type'],$param['name'],$param['code']));
    }

    /**
     * @title 订单详情
     * @description
     * @author fzf
     * @url /api/order/$sn
     * @method get
     */
    function info($sn,Check $check){
        return $this->success($check->info($sn));
    }


    /**
     * @title 订单支付
     * @description
     * @author fzf
     * @url /api/pay/$sn
     * @method post
     * @param name:platform type:string require:1 default:miniapp other: desc:平台：miniapp,h5
     */
    function pay($sn,Request $request,Check $check){
        $type=$request->input('platform','miniapp');
        return $this->success($check->pay($sn,$type));
    }

    /**
     * @title 支付状态
     * @description
     * @author fzf
     * @url /api/pay/$sn
     * @method get
     */
    function payInfo($sn,Check $check){
        return $this->success($check->payInfo($sn));
    }

    /**
     * @title 订单取消
     * @description
     * @author fzf
     * @url /api/pay/$sn
     * @method delete
     */
    function cancel($sn,Check $check){
        $check->cancel($sn);
        return $this->success();
    }
}
